﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace RelationUsingAnnotations
{
    /// <summary>
    /// EFCore中使用强制关系，Book删除后将级联删除对应作者、审稿人和编辑
    /// </summary>
    public class Book
    {
        public int BookId { get; set; }
        public string Title { get; set; }
        public List<Chapter> Chapters { get; } = new List<Chapter>();
        //使用？设置数据库对应列为可选项
        public int? AuthorId { get; set; }
        //限制作者的外键为AuthorId
        [ForeignKey(nameof(AuthorId))]
        public User Author { get; set; }      
        public int? ReviewerId { get; set; }
        //限制审稿人的外键为ReviewerId，使用强制关系EFCore将创建级联删除
        [ForeignKey(nameof(ReviewerId))]
        public User Reviewer { get; set; }
        public int? ProjectEditorId { get; set; }
        //限制编辑的外键为ProjectEditorId，使用强制关系EFCore将创建级联删除
        [ForeignKey(nameof(ProjectEditorId))]
        public User ProjectEditor { get; set; }
    }
}
